package com.ccys.cms.controller.userManagement;

import com.ccys.cms.service.userManagement.TblMemberWebService;
import com.ccys.common.constants.ContextConstants;
import com.ccys.common.util.Kit;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.userManagement.TblMemberDTO;
import com.ccys.db.entity.TblBookingBenefitConsult;
import com.ccys.db.entity.TblMember;
import com.ccys.db.vo.userManagement.TblMemberDetailWebVO;
import com.ccys.db.vo.userManagement.TblMemberSelectWebVO;
import com.ccys.db.vo.userManagement.TblMemberWebVO;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@Api(tags = "用户管理-patient-病人")
@RequestMapping("userManagement")
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE, RequestMethod.PUT}) // 开启跨域访问允许
@SuppressWarnings("unchecked")
public class MemberWebController {

    @Autowired
    private TblMemberWebService tblMemberWebService;

    // 用户管理下的  病人的 Consultations  与问诊模块下 通用张景灿写的接口

    @GetMapping("member")
    @ApiOperation("获取列表")
    @ApiImplicitParams({

            @ApiImplicitParam(name = "name", value = "firstName + lastName", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "nricFin", value = "nricFin", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "memberNo", value = "no 用户编号", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "phone", value = "Mobile", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "email", value = "email", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "gender", value = "0 女 1 男 -1 未知", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "startAge", value = "年龄范围开始（55xx以上传该字段）", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "endAge", value = "年龄范围结束（13xx以下传该字段）", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "newsLetter", value = "newsLetter", required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "status", required = false, dataType = "string", paramType = "query"),


            @ApiImplicitParam(name = "id", value = "对象id", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间(格式 yyyy-mm-dd)", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间(格式 yyyy-mm-dd)", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "orderByStr", value = "排序字段（后端返回的字段  asc升序，desc 降序,加上end后缀。示例（createdOn降序排 则传值 createdOn descend））",paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 411, message = ContextConstants.DESC_411),
            @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC,response = TblMemberWebVO.class)
    })
    public ResponseResult listObjectsCms(HttpServletRequest request, HttpServletResponse response, @ApiIgnore TblMemberDTO dto) {
        return this.tblMemberWebService.listObjectsCms(request, response, dto);
    }


    @GetMapping("member/listSelect")
    @ApiOperation("获取可选择用户列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "name", value = "firstName + lastName", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "nricFin", value = "nricFin", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "memberNo", value = "no 用户编号", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "phone", value = "Mobile", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "email", value = "email", required = false, dataType = "string", paramType = "query"),

    })
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC,response = TblMemberSelectWebVO.class)
    })
    public ResponseResult listSelect (HttpServletRequest request, HttpServletResponse response, @ApiIgnore TblMemberDTO dto) {
        return this.tblMemberWebService.listSelect(request, response, dto);
    }


    @GetMapping("member/detail")
    @ApiOperation("查询详情")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "对象id", required = false, dataType = "string", paramType = "query"),

    })
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC,response = TblMemberDetailWebVO.class)
    })
    public ResponseResult getMemberDetail(HttpServletRequest request, HttpServletResponse response, @ApiIgnore TblMemberDTO dto) {
        return this.tblMemberWebService.getMemberDetail(request, response, dto);
    }


    @PostMapping("member")
    @ApiOperation("添加")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "firstName", value = "Full name 的开始名", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "lastName", value = "Full name 的结束名", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "email", value = "email", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "password", value = "加密方式:PBKDF2-SHA1", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "gender", value = "0 女 1 男 -1 未知", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "singpassUuid", value = "singpassUuid", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "regdate", value = "注册日期(yyyy-mm-dd)", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "actived", value = "激活状态 Activated 1，  Pending activation 0", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "parentId", value = "家长/监护人账号 id  对应 patient Type， parentId 为空 标识self   ，不为空标识 child", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "relationship", value = "父账号关系 1parent 2guardian 3mother 4father", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "nricFin", value = "ID(身份ID)", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "dob", value = "生日", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "newsLetter", value = "newsLetter", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "type", value = "1:NRIC_FIN 2:Passport 3:Birth_certificate 4:Driving_license(other) 5:Child_photo", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "testAccount", value = "是否测试账号", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "height", value = "height", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "weight", value = "weight", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "aiaIdentifier", value = "aiaIdentifier", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "aiaMember", value = "aiaMember", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "phone", value = "Contact information 模块的", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "phoneCountryId", value = "Contact information 模块的区号传国家id", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "countryId", value = "Contact information 模块的 ", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "emergencyCountryId", value = "Emergency contact 模块的", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "emergencyFirstName", value = "Emergency contact 模块的 Full name 开始", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "emergencyLastName", value = "Emergency contact 模块的 Full name 结束", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "emergencyPhone", value = "Emergency contact 模块的 Phone", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "emergencyRelationship", value = "Emergency contact 模块的 Relationship", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "homeAddress", value = "Address 模块下的", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "locationFloorNumber", value = "Address模块下的 FloorNumber", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "currentCountry", value = "Address模块下的 Country", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "locationState", value = " Address模块下的 State", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "nationality", value = "国籍", required = false, dataType = "string", paramType = "query"),

        @ApiImplicitParam(name = "backDrivingLicense", value = "驾照反面", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "backGeneralCard", value = "某种卡的反面照", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "backIdentificationCard", value = "证件反面", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "birthCertificate", value = "出生证明照片", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "childPhoto", value = "childPhoto", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "frontDrivingLicense", value = "驾照正面", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "frontGeneralCard", value = "某种卡的正面照", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "frontIdentificationCard", value = "证件正面", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "g6pd", value = "g6pd", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "image", value = "头像", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "passport", value = "护照照片", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "status", value = "status", required = false, dataType = "string", paramType = "query"),

    })
    @ApiResponses({
            @ApiResponse(code = 411, message = ContextConstants.DESC_411),
            @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC)
    })
    public ResponseResult save(@ApiIgnore TblMember entity) {
        entity.setId(null);
        return this.tblMemberWebService.change(entity);
    }


    @PutMapping("member")
    @ApiOperation("编辑")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "对象id", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "firstName", value = "Full name 的开始名", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "lastName", value = "Full name 的结束名", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "email", value = "email", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "password", value = "加密方式:PBKDF2-SHA1", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "gender", value = "0 女 1 男 -1 未知", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "singpassUuid", value = "singpassUuid", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "regdate", value = "注册日期(yyyy-mm-dd)", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "actived", value = "激活状态 Activated 1，  Pending activation 0", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "parentId", value = "家长/监护人账号 id  对应 patient Type， parentId 为空 标识self   ，不为空标识 child", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "relationship", value = "父账号关系 1parent 2guardian 3mother 4father", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "nricFin", value = "ID(身份ID)", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "dob", value = "生日(yyyy-mm-dd)", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "newsLetter", value = "newsLetter", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "type", value = "1:NRIC_FIN 2:Passport 3:Birth_certificate 4:Driving_license(other) 5:Child_photo", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "testAccount", value = "是否测试账号", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "height", value = "height", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "weight", value = "weight", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "aiaIdentifier", value = "aiaIdentifier", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "aiaMember", value = "aiaMember", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "phone", value = "Contact information 模块的", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "phoneCountryId", value = "Contact information 模块的区号传国家id", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "countryId", value = "Contact information 模块的 ", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "emergencyCountryId", value = "Emergency contact 模块的", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "emergencyFirstName", value = "Emergency contact 模块的 Full name 开始", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "emergencyLastName", value = "Emergency contact 模块的 Full name 结束", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "emergencyPhone", value = "Emergency contact 模块的 Phone", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "emergencyRelationship", value = "Emergency contact 模块的 Relationship", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "homeAddress", value = "Address 模块下的", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "locationFloorNumber", value = "Address模块下的 FloorNumber", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "currentCountry", value = "Address模块下的 Country", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "locationState", value = " Address模块下的 State", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "nationality", value = "国籍", required = false, dataType = "string", paramType = "query"),

        @ApiImplicitParam(name = "backDrivingLicense", value = "驾照反面", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "backGeneralCard", value = "某种卡的反面照", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "backIdentificationCard", value = "证件反面", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "birthCertificate", value = "出生证明照片", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "childPhoto", value = "childPhoto", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "frontDrivingLicense", value = "驾照正面", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "frontGeneralCard", value = "某种卡的正面照", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "frontIdentificationCard", value = "证件正面", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "g6pd", value = "g6pd", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "image", value = "头像", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "passport", value = "护照照片", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "status", value = "status", required = false, dataType = "string", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 411, message = ContextConstants.DESC_411),
            @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC)
    })
    public ResponseResult edit(@ApiIgnore TblMember entity) {
        Kit.allParamValid(entity, "id");
        entity.setMemberNo(null);
        return this.tblMemberWebService.change(entity);
    }

    @PutMapping("member/updatePatientInfoConsultationsAdjust")
    @ApiOperation("病人info里面的Consultations的Adjust修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "分页返回时返回了个:(bookingBenefitConsultId)点击Adjust修改时必须带上", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "adjustmentReason", value = "adjustmentReason", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "claimAmount", value = "分页时返回为：consultTotalClaimable", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "visitCount", value = "visitCount", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "additionalClaimAmount", value = "additionalClaimAmount/非必传", required = false, dataType = "string", paramType = "query"),
    })
    public ResponseResult updatePatientInfoConsultationsAdjust(@ApiIgnore TblBookingBenefitConsult dto)  {
        return tblMemberWebService.updatePatientInfoConsultationsAdjust(dto);
    }


}